home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved */
- /*****************************************************************************/
- /* This source-code is NOT public domain nor Freeware, this is part of */
- /* 'The C Programming Package' which is Shareware. */
- /* If you use this code, please register and get a free Full-VGA version */
- /*****************************************************************************/
- /*------------------*
- * CPPLMAT2.C *
- * Hardware *
- * config (contd) *
- *------------------*/
-
- /* Included Files */
- # include <stdio.h>
- # include <io.h>
- # include <dos.h>
- # include <fcntl.h>
- # include <bios.h>
- # include <stdlib.h>
- # include <SYS\stat.h>
- # include <conio.h>
- # include <alloc.h>
- # include <process.h>
- # include <ctype.h>
- # include <string.h>
-
- /* Global Variables */
- extern int x,y,z,i,j,k,l,m,n,bm,xm,ym,return2,chx2;
- extern int colour1,colour2,colour3,colour4,colour5,chif,background,colourprov,colourchoice;
- extern unsigned char c1,nc1[],trashcan[];
-
- /*-----------------------*
- * GET COLOURS2 KEYBOARD *
- *-----------------------*/
- int get_colour2_keyboard()
- {
- j=get_key();
- if(j<16){
- /* We entered a legal number between 0 and f/F=15 */
- /* or -1 for <Esc> */
- return(j);
- }
- /* <Enter> confirms the modifications */
- if(c1==13) return(21);
- if((c1==66)||(c1==98)){
- /* We want to change the background = B b */
- chx2=1; return(21);
- }
- if((c1==70)||(c1==102)){
- /* If we want to change the foreground = F f */
- chx2=2; return(21);
- }
- if((c1==67)||(c1==99)){
- /* If we want to confirm the modifications = C c */
- chx2=3; return(21);
- }
- if((c1==81)||(c1==113)){
- /* If we want to quit without modifying = Q q */
- chx2=4; return(21);
- }
- /* Other cases : return 20 */
- return(20);
- }
- /*----------------------*
- * GET SPECIAL COLOUR 2 *
- *----------------------*/
- int get_special_colour2()
- {
- if(c1==59){
- /* On-line help */
- return(59);
- }
- if(c1==75){
- /* Left arrow */
- if(chx2>1) chx2--;
- }
- if(c1==77){
- /* Right arrow */
- if(chx2<4) chx2++;
- }
- /* In all the other cases we do not change nothing */
- /* but we return a value */
- return(20);
- }
- /*--------------------*
- * GET COLOURS2 MOUSE *
- *--------------------*/
- int get_colour2_mouse()
- {
- if((xm>3)&&(xm<58)&&(ym>5)&&(ym<21)){
- /* We are in the colours zone */
- if((xm>1)&&(xm<10)){
- /* We only change the background colour */
- background=(ym-6)/2; colourprov=(16*background)+chif;
- }
- if((xm>10)&&(xm<58)){
- /* We are in the colours grid we change both */
- background=(ym-6)/2; chif=(xm-11)/3;
- colourprov=(16*background)+chif;
- }
- }
- if(ym==22){
- /* With the mouse it is choice and confirmation */
- if((xm>3)&&(xm<16)){
- /* Change the background */
- chx2=1; return(21);
- }
- if((xm>16)&&(xm<29)){
- /* Change the chars */
- chx2=2; return(21);
- }
- if((xm>29)&&(xm<39)){
- /* Confirm the modifications */
- chx2=3; return(21);
- }
- if((xm>39)&&(xm<58)){
- /* Return without change */
- chx2=4; return(21);
- }
- }
- /* In all other cases we return 20 */
- return(20);
- }
- /*-----------------------*
- * DISPLAY CHOICE SCREEN *
- *-----------------------*/
- void display_choice_screen()
- {
- hide_the_mouse();
- /* We erase the used zone */
- textattr(15); window(2,3,59,24);
- clrscr(); window(1,1,80,25);
- /* We draw the grid */
- gotoxy(3,3); cputs("┌──────┬───────────────────────────────────────────────┐");
- gotoxy(3,4); cputs("│ Back.│ Characters colours │");
- gotoxy(3,5); cputs("├──────┼──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┤");
- gotoxy(3,6); cputs("│ 0 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,7); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,8); cputs("│ 1 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,9); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,10); cputs("│ 2 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,11); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,12); cputs("│ 3 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,13); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,14); cputs("│ 4 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,15); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,16); cputs("│ 5 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,17); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,18); cputs("│ 6 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,19); cputs("├──────┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤");
- gotoxy(3,20); cputs("│ 7 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │");
- gotoxy(3,21); cputs("╠══════╧══╧══╪══╧══╧══╧══╧╤═╧══╧══╧═╤╧══╧══╧══╧══╧══╧══╣");
- gotoxy(3,22); cputs("║ Background │ Foreground │ Confirm │Quit without modif║");
- gotoxy(3,23); cputs("╚════════════╧════════════╧═════════╧══════════════════╝");
- gotoxy(3,24); cputs(" Current colours. Your choice ( Keyboard or Mouse ) ");
- /* Fill it with the value and the colours */
- /* For the background */
- trashcan[0]=0x20; trashcan[1]=0x20;
- trashcan[2]=0x20; trashcan[3]=0x20;
- trashcan[4]=0x20; trashcan[5]=0x20;
- trashcan[6]=0x00;
- for(i=1; i<8; i++){
- k=(16*i)+15; textattr(k);
- itoa(i,nc1,10); trashcan[3]=nc1[0];
- gotoxy(4,(2*i)+6); cputs(trashcan);
- }
- /* And now the foreground */
- trashcan[2]=0x00;
- for(i=0; i<8; i++){
- for(j=0; j<16; j++){
- /* Calculate colour */
- k=(16*i)+j; itoa(j,nc1,16);
- /* Transform it in char j to display with right justification */
- trashcan[0]=0x20; trashcan[1]=nc1[0];
- /* Display it in the right colour */
- textattr(k);
- gotoxy(((3*j)+11),((2*i)+6)); cputs(trashcan);
- }
- }
- show_the_mouse();
- }
- /*--------------------------*
- * DISPLAY CHOICE COLOURS 2 *
- *--------------------------*/
- void display_choice_colour2()
- {
- hide_the_mouse(); textattr(15);
- gotoxy(4,22); cputs(" Background ");
- gotoxy(17,22); cputs(" Foreground ");
- gotoxy(30,22); cputs(" Confirm ");
- gotoxy(40,22); cputs("Quit without modif");
- textattr(116);
- gotoxy(5,22); cputs("B");
- gotoxy(18,22); cputs("F");
- gotoxy(31,22); cputs("C");
- gotoxy(41,22); cputs("Q");
- /* display this line with the current colours */
- textattr(colourprov);
- gotoxy(3,24); cputs(" Current colours. Your choice ( Keyboard or Mouse ) ");
- /* Then we outline the choice */
- textattr(112);
- if(chx2==1){
- gotoxy(4,22); cputs(" Background ");
- }
- if(chx2==2){
- gotoxy(17,22); cputs(" Foreground ");
- }
- if(chx2==3){
- gotoxy(30,22); cputs(" Confirm ");
- }
- if(chx2==4){
- gotoxy(40,22); cputs("Quit without modif");
- }
- show_the_mouse();
- }
- /*--------------------------*
- * COPY NEW VALUE IN COLOUR *
- *--------------------------*/
- void copy_new_value_in_colour()
- {
- if(colourchoice==1) colour1=colourprov;
- if(colourchoice==2) colour2=colourprov;
- if(colourchoice==3) colour3=colourprov;
- if(colourchoice==4) colour4=colourprov;
- if(colourchoice==5) colour5=colourprov;
- }
- /*-----------------------*
- * LOAD TEMPORARY COLOUR *
- *-----------------------*/
- void load_temporary_colour()
- {
- if(colourchoice==1) colourprov=colour1;
- if(colourchoice==2) colourprov=colour2;
- if(colourchoice==3) colourprov=colour3;
- if(colourchoice==4) colourprov=colour4;
- if(colourchoice==5) colourprov=colour5;
- }
- /*--------------------------*
- * CHANGE BACKGROUND COLOUR *
- *--------------------------*/
- void change_background_colour()
- {
- textattr(colourprov+128);
- gotoxy(3,24); cputs(" Enter the new background colour value. Your choice : ");
- gotoxy(57,24); c1=getch();
- z=get_colour2_keyboard();
- if((z>=0)&&(z<8)){
- background=z; colourprov=(16*background)+chif;
- }
- }
- /*--------------------------*
- * CHANGE FOREGROUND COLOUR *
- *--------------------------*/
- void change_foreground_colour()
- {
- textattr(colourprov+128);
- gotoxy(3,24); cputs(" Enter the new foreground colour value. Your choice : ");
- gotoxy(57,24); c1=getch();
- z=get_colour2_keyboard();
- if((z>=0)&&(z<16)){
- chif=z; colourprov=(16*background)+chif;
- }
- }
- /*-----------------*
- * CHOOSE A COLOUR *
- *-----------------*/
- void choose_a_colour()
- {
- /* Update the new choice right now */
- display_colour_choice(); display_choice_screen();
- chx2=1; load_temporary_colour();
- while(1){
- display_choice_colour2();
- while(1){
- if(kbhit()){
- /* If we pressed a key */
- c1=getch();
- if(c1==0){
- /* The key is coded in 2 bytes. Cut the Second one */
- c1=getch();
- return2=get_special_colour2(); break;
- }
- else{
- /* We pressed a keyboard key */
- return2=get_colour2_keyboard(); break;
- }
- }
- /* Else test the mouse */
- get_mouse_state();
- if(bm==1){
- /* We pressed a mouse button */
- return2=get_colour2_mouse(); break;
- }
- }
- /* We treat the result */
- if(return2==-1) return;
- if(return2==21){
- /* We confirmed or we pressed <Enter> to confirm */
- if(chx2==1){
- /* We want to change the background colour */
- change_background_colour();
- }
- if(chx2==2){
- /* We want to change the foreground colour */
- change_foreground_colour();
- }
- if(chx2==3){
- /* Return after copying the new color value */
- copy_new_value_in_colour();
- return;
- }
- if(chx2==4){
- /* Return without modifying the colour value */
- return;
- }
- }
- if(return2==22){
- /* F1 = On-line help */
- display_help("CONFIGUR",92,4,1); restore_help_screen();
- }
- }
- }
- /* End of the hardware config file */
-
-